// load WB data related to health

cd "~/Documents/econ/research/current/cognitive/estimation/data"

wbopendata, clear year(1960:2020) long nometadata indicator( ///
	ny.gdp.mktp.kd;		/// GDP (constant 2010 US$)
 	ny.gdp.mktp.pp.kd;	/// GDP, PPP (constant 2017 international $)	
	ne.imp.gnfs.cd;		/// Imports of goods and services (current US$)
	ne.exp.gnfs.cd; 	/// Exports of goods and services (current US$)
	ny.gdp.mktp.cd;		/// GDP at market prices (current US$)
	ny.gnp.pcap.cd;		/// GNI per capita, Atlas method (current US$)
/// sanitation and water
	sh.sta.bass.zs;		/// People using >=basic sanitation (% of pop)
	sh.sta.smss.zs;		/// People using safely managed sanitation (% of pop)
	sh.sta.odfc.zs;		/// People practicing open defecation (% of population)
	sh.h2o.basw.zs;		/// People using >= basic drinking water (% of pop)
	sh.sta.orth;		/// Diarrhea treatment (% children < 5 received ORS)
/// nutrients and vaccines
	sh.anm.chld.zs;  	/// Prevalence of anemia (% children < 5)
	sn.itk.salt.zs;		/// Consumption of iodized salt (% of households)
    sh.imm.ibcg;		/// Vaccinations (BCG) (% of children ages 12-23 months)
	sh.imm.hepb;		/// Immunization, HepB3 (% of one-year-old children)
	sh.imm.idpt;		/// Immunization, DPT (% of children ages 12-23 months)
	sh.imm.meas;		/// Immunization, measles (% of children ages 12-23 months)
	sh.dyn.aids.zs;   	/// Prevalence of HIV, total (% of population ages 15-49)	
/// pregnancy
	sp.ado.tfrt;		/// Adolescent fertility rate (births per 1,000 women ages 15-19)
	sh.anm.allw.zs;		/// Prev. anemia, women reprod. age (% women ages 15-49)
	sh.sta.brtw.zs;  	/// Low-birthweight babies (% of births)
	sh.sta.anvc.zs;		/// Pregnant women receiving prenatal care (%)
	sh.sta.bfed.zs;		/// Exclusive breastfeeding (% of children under 6 months)
/// malnutrition
	sn.itk.defc.zs;		/// Prevalence of undernourishment (% of population)
	sh.sta.stnt.zs;     /// Prevalence of stunting, height for age (% children < 5)	
	sh.sta.wast.zs;		/// Prevalence of wasting, weight for height (% children < 5)	
	sh.svr.wast.zs;		/// Prev. of severe wasting, weight for height (% children < 5)
	sh.sta.maln.zs;		/// Prevalence of underweight, weight for age (% children < 5)
/// mortality
	sp.dyn.imrt.in;		/// Mortality rate, infant (per 1,000 live births)
	sh.dyn.mort;		/// Mortality rate, under-5 (per 1,000 live births)
	sh.mmr.risk.zs;		/// Lifetime risk of maternal death (%)
	sh.sta.mmrt;		/// Maternal mort ratio (modeled est., /100,000 live births)
	sh.sta.mmrt.ne;		/// Maternal mort ratio (national est., /100,000 live births)
/// disease
	sh.sta.aric.zs;		/// Acute respiratory infection (ARI) treatment (% of children < 5)
	sh.prv.smok;		/// Smoking prevalence, total (ages 15+)
	sh.sta.airp.fe.p5;	/// Air pollution female mortality (per 100,000)
/// health care
	sh.xpd.chex.gd.zs;	/// Current health expenditure (% of GDP)
	sh.xpd.pvtd.ch.zs;  /// Domestic private health expenditure (% health expenditure)	
	sh.sta.brtc.zs;		/// Births attended by skilled health staff (% of total)
	sh.med.cmhw.p3;		/// Community health workers (per 1,000 people)
	sh.med.phys.zs;		/// Physicians (per 1,000 people)
	sp.urb.totl.in.zs;	/// Urban population (% of total)
/// Women's education
	bar.schl.15up.fe;		/// Avg yrs of school, age 15+, female
	bar.schl.15up;			/// Avg yrs of school, age 15+
	bar.sec.schl.15up.fe;	/// Avg yrs secondary school, age 15+, female
	bar.prm.cmpt.15up.fe.zs;	/// % females 15+ with primary school
	bar.sec.cmpt.15up.fe.zs)	/// % females 15+ with secondary school
	
// keep if mod(year,5)==0  // only keep every 5 years

rename countryname 		country
rename ny_gdp_mktp_kd	gdpWDI  	// GDP (constant 2005 US$)
rename ny_gdp_mktp_pp_kd gdpPPPWDI	// GDP, PPP (constant 2011 international $)
rename ny_gnp_pcap_cd 	gnipc_curr	// GNI per capita, Atlas method (current US$)

/// sanitation and water
rename sh_sta_bass_zs	sanitation	// People using >= basic sanitation (% pop)
rename sh_sta_smss_zs	sani_manag	// People w/ safely managed sanitation (% pop)
rename sh_sta_odfc_zs	defecate	// Open defecation (% pop)
rename sh_h2o_basw_zs	water		// People using >= basic drinking water (% pop)
rename sh_sta_orth		diar_ort	// Diarrhea treatment (% children < 5 received ORS)
/// nutrients and vaccines
rename sh_anm_chld_zs 	anemia 		// Prevalence of anemia (% children < 5)
rename sn_itk_salt_zs   iodiz_salt  // Consumption of iodized salt (% households)
rename sh_imm_hepb      hepb        // Immunization, HepB3 (% one y.o. children)
rename sh_imm_idpt		dpt 		// Immunization, DPT (% children 12-23 months)
rename sh_imm_meas		measles		// Immunization, measles (% children 12-23 months)
rename sh_imm_ibcg      bcg         // Vaccinations (BCG) (% children 12-23 months)
rename sh_dyn_aids_zs	hiv			// Prevalence of HIV, total (% pop 15-49)	
/// pregnancy
rename sp_ado_tfrt      teenbirth   // Adolescent fertility (births/1000 women 15-19)
rename sh_anm_allw_zs   w_anemia    // Anemia, women reprod. age (% women 15-49)
rename sh_sta_brtw_zs  	low_birth	// Low-birthweight babies (% of births)
rename sh_sta_anvc_zs   prenat_care // Pregnant women receive prenatal care (%)
rename sh_sta_bfed_zs   breastfed   // Exclusive breastfeed (% children < 6 months)
/// malnutrition
rename sn_itk_defc_zs  	undernut 	// Prevalence of undernourishment (% of population)
rename sh_sta_stnt_zs  	stunting 	// Stunting, height for age (% children < 5)
rename sh_sta_wast_zs  	wasting 	// Wasting, weight for height (% children < 5)
rename sh_svr_wast_zs  	svr_waste 	// Severe wasting, weight for height (% children < 5)
rename sh_sta_maln_zs   underwgt    // Prev. underweight, weight for age (% children < 5)	
/// mortality
rename sp_dyn_imrt_in   imr_wb      // Mortality rate, infant (per 1,000 live births)
rename sh_dyn_mort      cmr_wb      // Mortality rate, under-5 (per 1,000 live births)
rename sh_mmr_risk_zs   matermort   // Lifetime risk of maternal death (%)
rename sh_sta_mmrt      mmr         // Mater. mort. ratio (modeled, /100,000 live births)
rename sh_sta_mmrt_ne   mmr_ne      // Mater. mort. ratio (national est, /100,000 births)
/// disease
rename sh_sta_aric_zs	ari5		// Acute resp infect (ARI) treatment (% of children < 5)
rename sh_prv_smok		smoking		// Smoking prevalence, total (ages 15+)
rename sh_sta_airp_fe_p5 airpoll	// Air pollution female mortality (per 100,000)
/// healthcare
rename sh_xpd_chex_gd_zs hs_pct     // Health expenditure (% GDP)
rename sh_xpd_pvtd_ch_zs hs_priv 	// Private health exp (% of health exp)
rename sh_sta_brtc_zs	skillbirth	// Births attended by skilled health staff (% of total)
rename sh_med_cmhw_p3	healthwork	// Community health workers (per 1,000 people)
rename sh_med_phys_zs	phys		// Physicians (per 1,000 people)
rename sp_urb_totl_in_zs urban		// Urban population (% of total)
/// women's education
rename bar_schl_15up_fe		sch_f15_		// Avg yrs of school, age 15+, female
gen sch_m15_ = 2*bar_schl_15up - sch_f15_	// Avg yrs of school, age 15+, male
drop bar_schl_15up
rename bar_sec_schl_15up_fe	sch_sec_f15_	// Avg yrs secondary school, age 15+, female
rename bar_prm_cmpt_~e 		prim_f15_	// % females 15+ with primary school
rename bar_sec_cmpt_~e 		sec_f15_	// % females 15+ with secondary school

gen trade_open = (ne_imp_gnfs_cd + ne_exp_gnfs_cd)/ny_gdp_mktp_cd*100
label var trade_open "Trade openness = %(imp+exp)/gdp"
drop ne_imp_gnfs_cd ne_exp_gnfs_cd ny_gdp_mktp_cd

label var gdpWDI "GDP (constant 2010 US$)"
label var gdpPPPWDI "PPP GDP (constant 2017 $)"
/// sanitation and water
label var sanitation "Basic sanitation facilities (% pop with access)"
label var sani_manag "Safely managed sanitation (% pop with access)"
label var defecate "Prev. open defecation (% pop)"
label var water "Basic drinking water (% pop with access)"
/// nutrients and vaccines
label var anemia "Prevalence of anemia (% children < 5)"
label var hepb "Immunization, HepB3 (% one y.o. children)"
label var dpt "Immunization, DPT (% of children ages 12-23 months)"
label var measles "Immunization, measles (% of children ages 12-23 months)"
label var bcg "Vaccinations (BCG) (% children 12-23 months)"
label var hiv "Prevalence of HIV, total (% of population ages 15-49)"
/// pregnancy
label var teenbirth "Adolescent fertility (births/1000 women 15-19)"
label var w_anemia "Anemia, women reprod. age (% women 15-49)"
label var low_birth "Low-birthweight babies (% of births)"
/// malnutrition
label var undernut "Prevalence of undernourishment (% of population)"
/// mortality
label var imr_wb "WB infant mortality rate (per 1,000 live births)"
label var cmr_wb "WB under-5 mortality rate (per 1,000 live births)"
label var matermort "Lifetime risk of maternal death (%)"
label var mmr "Mater. mort. ratio (modeled, /100,000 live births)"
label var mmr_ne "Mater. mort. ratio (national est, /100,000 births)"
/// health spending
label var hs_priv "Private health expenditure (% of total)"

/// women's education
label var sch_f15_	"Avg yrs of school, age 15+, female"
label var sch_m15_ 	"Avg yrs of school, age 15+, male"
label var sch_sec_f15_	"Avg yrs secondary school, age 15+, female"
label var prim_f15_	"% females 15+ with primary school"
label var sec_f15_	"% females 15+ with secondary school"


drop region*
rename adminregion region
rename adminregionname regname
replace region = "HIC" if incomelevel=="HIC"
replace regname = "High Income Country" if incomelevel=="HIC"
// drop all the multi-country aggregates
drop if region==""
/*
// drop if length(countrycode)>3  // lots of Indonesia region codes!!
drop if countrycode == "CEB" | ///
	countrycode == "EAR" | ///
	countrycode == "FCS" | ///
	countrycode == "IBD" | ///
	countrycode == "IBT" | ///
	countrycode == "IDA" | ///
	countrycode == "IDB" | ///
	countrycode == "IDX" | ///
	countrycode == "LTE" | ///
	countrycode == "PRE" | ///
	countrycode == "PST" | ///
	countrycode == "TEA" | ///
	countrycode == "TEC" | ///
	countrycode == "TLA" | ///
	countrycode == "TMN" | ///
	countrycode == "TSA" | ///
	countrycode == "TSS"
*/

// add World Bank country income categories
merge m:1 year using WB_inc_cat
gen byte wb_cat = 1 + (gnipc_curr > low_inc) + (gnipc_curr > low_mid)	///
	+ (gnipc_curr > up_mid) if (year>=1985 & gnipc_curr<.)
label define wblbl 1 "LI" 2 "LM" 3 "UM" 4 "HI"
label values wb_cat wblbl
label var wb_cat "World Bank income categories"
drop _merge low_inc low_mid up_mid gnipc_curr

order country countrycode year region regname wb_cat
drop incomelevel-lendingtypename
compress
sort countrycode year
saveold WDI, replace version(11)
